@extends('admin.main')

@section('content')
	<div class="row wrapper border-bottom white-bg page-heading">
		<div class="col-sm-4">
			<h2>{{$role->fullname}} <small>{{$role->name}}</small></h2>
			<strong>{{$role->description}}</strong>
		</div>
	</div>
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="m-b">
			<a href="{{session('listUrl')}}" class="btn btn-default m-r"><i class="fa fa-arrow-left"></i> 返回列表</a>
		</div>
		<div class="ibox">
			<div class="ibox-title">
				<h5><span class="text-danger">{{$role->fullname}}</span>权限列表 <small>请勾选为其授权</small></h5>
			</div>
			<div class="ibox-content">
				<table id="tblDataList" class="table table-hover table-bordered">
					<thead>
						<tr>
							<th width="60"><a href="javascript:;" onclick="checkAll()">全选</a></th>
							<th>权限</th>
							<th>权限名</th>
							<th>描述</th>
						</tr>
					</thead>
					<tbody>
						@foreach($perms as $row)
						<tr data-id="{{$row->id}}">
							<td class="text-center">
								<label class="i-checks">
									<input type="checkbox" value="{{$row->id}}" class="js-check" {{ in_array($row->id, $cur_perm_ids) ? 'checked=""' : '' }} />
								</label>
							</td>
							<td>{{$row->name}}</td>
							<td>{{$row->display_name}}</td>
							<td>{{$row->description}}</td>
						</tr>
						@endforeach
					</tbody>
				</table>
			</div>
		</div>
	</div>
@endsection

@section('pageheader')
	<link href="{{asset('assets/iCheck/custom.css')}}" rel="stylesheet">
@endsection

@section('pagescript')
	<script src="{{asset('assets/iCheck/icheck.min.js')}}"></script>
	<script src="{{asset('assets/models/roleModel.js')}}"></script>
	<script>
		var artDialog, role_id='{{$id}}';
		$("#side-menu li[rel='entrust']").addClass("active")
			.find("ul").addClass("in")
			.find("li[rel='1']").addClass("active");

		$('.i-checks').iCheck({
	    checkboxClass: 'icheckbox_square-green',
	    radioClass: 'iradio_square-green',
	  });

	  var checkAll = function(){
	    $(".js-check").iCheck("check");
	  };

	  $(".js-check").on('ifChanged', function(){
	  	var checked = $(this).prop("checked");
	  	if(checked){
		 		roleModel.addPerm({'id':role_id,'perm_id':$(this).val()}, null, failure);
		 	}else{
		 		roleModel.removePerm({'id':role_id,'perm_id':$(this).val()}, null, failure);
		 	}
	  });
	</script>
@endsection